package  
{
  import com.bit101.components.PushButton;
  import flash.display.Sprite;
	/**
   * ...
   * @author ivan
   */
  public class ScoreBoard extends Sprite
  {
    private var anagramUtil:AnagramUtil;
    
    public function ScoreBoard(result:PlayerResult, endFunction:Function) 
    {      
      for (var i:int = 0; i < 9; i++)
      {
        // Fake results
        var r:PlayerResult = new PlayerResult();
        var ridx:int = Math.random() * result.wordList.length;
        r.word = result.wordList[ridx];
        r.enabled = false;
        results.push(r);
      }
      
      results.push(result);
      
      results.sort(longestResultFirst);
      
      for (i = 0; i < results.length; i++)
      {
        r = results[i];
        r.position = i + 1;
        
        r.x = 150;
        r.y = 50 + 20 * i;
        
        addChild(r);
      }
      
      addChild(new LetterView(result.letters));
      
      var pb:PushButton = new PushButton(this, 424 - 150, 230, "OK", endFunction);
      pb.height = 40;
      
    }
    
    private function longestResultFirst(a:PlayerResult, b:PlayerResult):Number
    {
      if (a.word.length < b.word.length) return 1;
      if (a.word.length > b.word.length) return -1;
      return 0;
    }
    
    private var results:Vector.<PlayerResult> = new Vector.<PlayerResult>();
    
  }

}
